using System;
using System.Reflection;
using ClientTools.Library.Interfaces;

namespace ClientTools.Client.Library.Provider
{
    public sealed class ProviderManager
    {
        private static ProviderInfoCollection _providerInfos;

        public static ProviderInfoCollection ProviderInfos
        {
            get
            {
                if (_providerInfos == null)
                {
                    _providerInfos = new ProviderInfoCollection();

                    foreach (var t in Assembly.GetExecutingAssembly().GetTypes())
                    {
                        var i = t.GetInterface(typeof(IProvider).Name);
                        if (i != null)
                            _providerInfos.Add(new ProviderInfo
                                                   {
                                                       ProviderName = ((IProvider) Activator.CreateInstance(t)).ProviderName,
                                                       ProviderType = t
                                                   });
                    }
                }
                return _providerInfos;
            }
        }
    }
}
